<?php

class DefaultController extends Controller {

    /**
     * Lists all models.
     */
    public function actionIndex() {
        $this->layout = 'column1';
        $criteriaCategory = new CDbCriteria(array(
            'condition' => 'cat=1 and status=1',
            'order' => 'id ASC',
        ));
        $catgory = ProductCategory::model()->findAll($criteriaCategory);
        $criteria = new CDbCriteria(array(
            'condition' => 'status=1',
            'order' => 'id DESC',
        ));
        $criteria->addSearchCondition('product_sub', Product::SPNEW);
        $dataProvider = new CActiveDataProvider('Product', array(
            'pagination' => array(
                'pageSize' => '6',
            ),
            'criteria' => $criteria,
        ));
        $criteria1 = new CDbCriteria(array(
            'condition' => 'status=1',
            'order' => 'id DESC',
        ));
        $criteria1->addSearchCondition('product_sub', Product::SPNEW);
        $dataProvider1 = new CActiveDataProvider('Product', array(
            'pagination' => array(
                'pageSize' => '12',
            ),
            'criteria' => $criteria,
        ));

        $this->render('index', array('dataProvider' => $dataProvider, 'dataProvider1' => $dataProvider1, 'category' => $catgory));
    }

    public function findCategory($id) {
        $criteria = new CDbCriteria(array(
            'condition' => 'root=' . $id,
            'order' => 'id DESC',
        ));
        $model = ProductCategory::model()->findAll($criteria);
        return $model;
    }

    public function findProduct($id) {
        $criteria = new CDbCriteria();
        $criteria->addSearchCondition('category_id', $id);
        $model = Product::model()->findAll($criteria);
        return $model;
    }

}